# -*- coding: utf-8 -*-
# @Time    : 2018/12/20 14:52
# @Author  : zjj
# @Email   : 1933860854@qq.com
# @File    : yiShengUserApiView.py
# @Software: PyCharm
from .models import yiShengUser
from .serializer import YiShengUserSerializer
from rest_framework.views import APIView
from rest_framework.permissions import DjangoModelPermissions
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from rest_framework.pagination import PageNumberPagination
# 'Authorization': 'JWT token'
class StandardPageNumberPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = "page_size"
    page_query_param = 'page'
    max_page_size = 200
class YiShengUserApiView(APIView):
    queryset = yiShengUser.objects.all()
    authentication_classes = [JSONWebTokenAuthentication, ]
    permission_classes = [DjangoModelPermissions, ]
    def get(self, request):
        user = yiShengUser.objects.all().order_by('id')
        pg = StandardPageNumberPagination()
        page_roles = pg.paginate_queryset(queryset=user, request=request, view=self)
        serializer = YiShengUserSerializer(instance=page_roles, many=True)
        return pg.get_paginated_response(serializer.data)#Response(serializer.data)

yisheng_user = YiShengUserApiView.as_view()